package com.example.ktsb

import com.example.ktsb.entity.Message
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.context.annotation.ComponentScan
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RestController

@SpringBootApplication
class KtSbApplication

fun main(args: Array<String>): Unit = runBlocking {
    launch {
        repeat(10) {
            delay(1000)
            println("==============This is Kotlin Coroutine================")
        }
    }
    runApplication<KtSbApplication>(*args)
}

@RestController
class MessageResource {
    @GetMapping
    fun index(): List<Message> = listOf(
        Message("1", "Hello"),
        Message("2", "Kotlin"),
        Message("3", "Spring Boot"),
        Message(null, "?表示可为空")
    )

    @GetMapping("index2")
    fun index2(): Map<String, Message> = sortedMapOf(
        "b" to Message("2", "Kotlin"),
        "a" to Message("1", "Hello"),
        "c" to Message("3", "Spring Boot")
    )
}
